@{
ViewData["Title"]="管理员管理";
var managers = ViewBag.Data.Managers;
var pagebar = ViewBag.Data.PageBar;
}

<div class="card"
     style="min-height:400px;">
  <div class="card-header d-flex justify-content-between">
    <span>管理员列表</span>
    <button type="button"
            class="btn btn-primary"
            id="btn-addnew">新增</button>
  </div>
  <div class="card-body">

    <table class="table table-bordered">
      <thead class="thead-light">
        <tr>
          <th>姓名</th>
          <th>电话</th>
          <th>性别</th>
          <th style="width: 200px;">操作</th>
        </tr>
      </thead>
      <tbody>
        @foreach (var m in managers){
        <tr>
          <td>@m.Name</td>
          <td>@m.Phone</td>
          <td>@m.Sex</td>
          <td>
            <button type="button"
                    class="btn btn-warning btn-update"
                    data-managerid="@m.ManagerID">修改</button>&nbsp;
            <button type="button"
                    class="btn btn-danger btn-del"
                    data-name="@m.Name"
                    data-managerid="@m.ManagerID">删除</button>
          </td>
        </tr>
        }
      </tbody>
    </table>
  </div>
  <div class="card-footer d-flex justify-content-end"
       style="height:400px">
    <nav aria-label="..."
         class="mt-1">
      <ul class="pagination">
        <li class='page-item @(pagebar.CurrentPage==1?"disabled":"")'>
          <a class="page-link"
             asp-area="admin"
             asp-controller="Manager"
             asp-action="GetPage"
             asp-route-page="@pagebar.Previous"
             asp-route-pageSize="@pagebar.PageSize">Previous</a>
        </li>
        @foreach(var btn in pagebar.ButtonGroup){
        <li class='page-item @(pagebar.CurrentPage==btn?"active":"")'>
          <a class="page-link"
             asp-area="admin"
             asp-controller="Manager"
             asp-action="GetPage"
             asp-route-page="@btn"
             asp-route-pageSize="@pagebar.PageSize">@btn</a>
        </li>
        }
        <li class='page-item @(pagebar.CurrentPage==pagebar.PageCount?"disabled":"")'>
          <a class="page-link"
             asp-area="admin"
             asp-controller="Manager"
             asp-action="GetPage"
             asp-route-page="@pagebar.Next"
             asp-route-pageSize="@pagebar.PageSize">Next</a>
        </li>
      </ul>
    </nav>
  </div>
</div>

@section DemoScripts{
<script>
  $(function () {
    //激活菜单项
    $("#menu_managers").addClass("active");
    //删除处理
    $(".btn-del").on("click", function () {
      let btn = $(this);
      let msg = `是否删除【${btn.data("name")}】,请确认`;
      if (!confirm(msg)) return;
      $.ajax({
        type: "delete",
        url: `/admin/managers/info/${btn.data("managerid")}`,
        success: function (response) {
          alert(response.message);
          if (response.status == 0) location.reload();
        }
      });
    });

    //修改处理
    $(".btn-update").on("click", function () {
      location.href = `/admin/managers/info/${$(this).data("managerid")}`;
    })
    //新增处理
    $("#btn-addnew").on("click", function () {
      location.href = "/admin/managers/info/0"
    })

  });
</script>
}
